<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page
	import="com.onlineMIS.ORM.entity.headQ.barcodeGentor.*,java.util.Date,java.text.SimpleDateFormat"%>
<html>
<head>
<!-- 用于条码图片查找页面 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<title>查询条形码</title>
<%@ include file="../../common/Style.jsp"%>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/conf_files/js/BarcodeSearchKeys.js"></script>

<script type="text/javascript"
	src="<%=request.getContextPath()%>/conf_files/js/HtmlTable.js"></script>
<script>
var dataGrid ;
$(document).ready(function(){
	parent.$.messager.progress('close'); 
	jQuery.excel('InnerTableContent');
	$("#brandName").focus();
	$("#brandNums").val(0);
	
	var params= $.serializeObject($('#barcodeSearchForm'));
    
    dataGrid =  $('#dataGrid').datagrid({
		url : 'action/productJSONAction!searchImg',
		queryParams: params,
		fit : true,
		fitColumns : true,
		pagination : true,
		pageSize : 10,
		pageList : [ 10, 15],
		border : false,
		checkOnSelect : false,
		selectOnCheck : false,
		singleSelect:true,
		showFooter:true,
		columns : [ [
					{field:'year', width:5,title:'年份',align: 'center',formatter: function(value,row,index){
						return row.year + row.quarter;
					}},					
					{field:'brand', width:10,align: 'center',title:'品牌'},
					{field:'barcode', width:10,align: 'center',title:'条码'},
					{field:'categoryLevel1', width:5,align: 'center',title:'产品线'},
					{field:'category', width:10,align: 'center',title:'货品类别'},
					{field:'productCode', width:5,align: 'center',title:'货号'},
					{field:'factoryCode', width:5,align: 'center',title:'厂家货号'},
					{field:'color', width:10,align: 'center',title:'颜色'},
					{field:'salesPrice', width:5,align: 'center',title:'千禧吊牌价'},
					{field:'inventory', width:5,align: 'center',title:'当前库存'},
					{field:'img',
						width:10,
						
						title:'图片',
						formatter : function(value, row, index) {
							var str = '';
							str += $.formatString('<a href="#" onclick="viewImgP(\'{0}\');" ><img width="55" height="55" src='+value+'></a>',row.barcode);
							return str;
						}},
					
			     ]],
		toolbar : '#toolbar',
		
	});
});
/**
 * to ensure user has select some criteria
 */
function validateSearch(){
	$("#brands").find("option").attr("selected","selected"); 
	var area = $("#area_ID").val();
	var year = $("#year_ID").combobox('getValue');
	var quarter = $("#quarter_ID").combobox('getValue');
	var brand = $("#brands").val();
	var category = $("#category_ID").combobox('getValue');
	var productCode = $("#productCode").val();
	var barcode = $("#barcode").val();
	var time = $("#needCreateDate").is(':checked');
	if (year==0 && quarter==0 && brand==null && category==0 && productCode == "" && barcode=="" && time==false){
		alert("请在选项（年份，季度，品牌，货品，货号，条形码，录入时间）中选出你的条码范围，否则数据量太庞大!");
		return false;
	} else
		return true;
}


function searchBarcode(){
	var categoryId = $("#category_ID").combobox("getValue");
	if (categoryId != "0" && !isValidPositiveInteger(categoryId)){
		alert("货品类别不是一个正确的输入");
		return;
	}

    if (validateSearch()){
    	var params= $.serializeObject($('#barcodeSearchForm'));
    	$('#dataGrid').datagrid('load',params); 
    }
}

/**
 * 清空查询条件
 */
function deleteSearch(){
	$("#category_level_ID").combobox('setValue',null);
	$("#category_ID").combobox('setValue',null);
	$("#productCode").textbox("setValue",null)
	$("#barcode").textbox("setValue",null)
	$("#brandName").textbox("setValue",null)
	removeBrand();
}


/**
 * 查看图片详情
 */
function viewImgP(barcode){
	viewImg(barcode);
}


function removeBrand(){
	$("#brands").find("option:selected").each(function(){
	   var removeColor = $(this).val();
	   if (removeColor != 0 && removeColor != undefined)
		   $("#brands option[value='"+removeColor+"']").remove();  
       });
}
/**
 * once click the button, it will help to search brand
 */
function searchBrand(){	
	
	var brandName = $.trim($("#brandName").val());
	if (brandName != "") {
	    var params= "formBean.productBarcode.product.brand.brand_Name=" + brandName  ; 
    
        var url = encodeURI(encodeURI("productJSPAction!scanBrand?" +params));
	
        window.open(url,'_blank','height=450, width=450, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');  
	} else {
        alert("请输入品牌名称");
    } 
}

/**
 * user click the brand
 */
function selectHqBrand(brandName, brandId){

	if (brandName != "" && brandId != "" && brandId != 0){
		 $("#brandName").textbox("setValue",brandName)
    }
    
	var added = false;
     $("#brands option").each(function(){
     	   if($(this).val() == brandId)
     	      added = true;
     	   });
    if (added == false)
       $("#brands").append("<option selected value='"+ brandId+"'>"+ brandName+"</option>");
}
</script>


</head>
<body>
	<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',border:false" style="height: 130px;">
			<s:form id="barcodeSearchForm" action="" method="POST" theme="simple">
				<input type="hidden" id="isInitialized"
					name="formBean.isInitialized" />
					<table width="98%" align="center" class="OuterTable">
						<tr>
							<td>
								<table width="100%" border="0">
									<tr>
										<td height="31" colspan="7">
											<table width="100%" border="0">
												<tr class="PBAOuterTableTitale">
													<td height="31" colspan="10">总部货品图片查找:
													</td>
												</tr>			
												<tr class="InnerTableContent">
													<td width="4%" height="19" align="center"><strong>年份：</strong></td>
													<td width="10%"><s:select cssClass="easyui-combobox" style="width:125px;text-align: center"
															name="formBean.productBarcode.product.year.year_ID" size="1"
															id="year_ID" list="uiBean.basicData.yearList" listKey="year_ID" data-options="editable:false"
															listValue="year" /></td>
													<td width="4%" align="center"><strong>季度：</strong></td>
													<td width="10%"><s:select cssClass="easyui-combobox" style="width:125px;text-align: center"
															name="formBean.productBarcode.product.quarter.quarter_ID"
															size="1" id="quarter_ID" list="uiBean.basicData.quarterList"
															listKey="quarter_ID" listValue="quarter_Name"   data-options="editable:false"
															 /></td>
													<td width="4%" align="center"><strong>归属:</strong></td>
													<td width="10%"><s:select  cssClass="easyui-combobox" style="width:135px;text-align: center"
															name="formBean.headBrand"
															size="1" id="headBrand" list="uiBean.headqBrands"
															listKey="id" listValue="name"  data-options="editable:false"
															 /></td>
													<td width="4%" align="center"><strong>产品线：</strong></td>
													<td width="12%"><s:select  style="width:130px;text-align: center"
							 								name="formBean.productBarcode.product.categoryLevel1.category_ID"
															size="1" cssClass="easyui-combobox" id="category_level_ID"
															data-options="prompt:'请选择产品线',editable:false" 
															list="uiBean.basicData.categoryLevelList" listKey="category_ID"
															listValue="category_Name" headerKey="0" headerValue="" /></td>		 
													<td width="6%"><strong>货品类：</strong></td>
													<td><s:select  style="width:145px;text-align: center"
															name="formBean.productBarcode.product.category.category_ID"
															size="1" cssClass="easyui-combobox" id="category_ID"
															data-options="prompt:'请选择货品类'"
															list="uiBean.basicData.categoryList" listKey="category_ID"
															listValue="category_Name" headerKey="0" headerValue="" /></td>																										
												</tr>
												<tr class="InnerTableContent">
													<td align="center"><strong>货号：</strong></td>
													<td><input type="text"  class="easyui-textbox" data-options="prompt:'请输入产品货号'"
														name="formBean.productBarcode.product.productCode"
														id="productCode" title="产品货号" /></td>
													<td align="center"><strong>条码：</strong></td>
													<td><input type="text" name="formBean.productBarcode.barcode"  class="easyui-textbox" data-options="prompt:'请输入产品条码'"
														id="barcode" title="请输入12位的条码" /></td>
																					
													<td colspan="4"><%@ include
														file="../barcodeGentor/BrandInput.jsp"%></td>
													
													<td><strong>厂家货号:</strong></td>
													<td><input type="text"  class="easyui-textbox" data-options="prompt:'请输入厂家货号'"
														name="formBean.productBarcode.product.factoryCode"
														id="factoryCode" title="厂家货号" /></td>															
												</tr>											
											</table>
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>

			</s:form>
		</div>
		<div data-options="region:'center',border:false" >						
			<table id="dataGrid">
			</table>
		
			<div id="toolbar" style="display: none;">				
				<a onclick="searchBarcode();" href="javascript:void(0);"
					class="easyui-linkbutton" 
					data-options="iconCls:'icon-search',plain:true">查询条码信息</a>
				<a onclick="deleteSearch();" href="javascript:void(0);"
					class="easyui-linkbutton" 
					data-options="iconCls:'icon-no',plain:true">清空查询</a>				
			</div>		
		</div>
	</div>
</body>
</html>